﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Net;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;


namespace WebCrawler
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("testing");

            string url = "https://services3.cic.gc.ca/ecas/authenticate.do";

            //HttpWebResponse response = HttpWebResponseUtility.CreateGetHttpResponse(url, 5000, null, null);

            IDictionary<string, string> parameters = new Dictionary<string, string>();  
            parameters.Add("lang", "");  
            parameters.Add("_page", "_target0");
            parameters.Add("app", "ecas");  
            parameters.Add("identifierType", "1");  
            parameters.Add("identifier", "90091478");  
            parameters.Add("surname", "CHEN");  
            parameters.Add("dobDay", "03");  
            parameters.Add("dobMonth", "08");  
            parameters.Add("dobYear", "1980");  
            parameters.Add("countryOfBirth", "202");  
            parameters.Add("_submit", "Continue");


            HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(url, parameters, 5000, null, Encoding.UTF8, null);
            string cookieString = response.Headers["Set-Cookie"];

            CookieCollection cookies = new CookieCollection();

            HttpWebResponse res = HttpWebResponseUtility.CreateGetHttpResponse("https://services3.cic.gc.ca/ecas/viewcasestatus.do?app=ecas", 5000, null, cookies);
            

            //HTTPSRequest.ProcessRequest();



            Stream resStream = response.GetResponseStream();
            

            ////可根据实际保存为具体文件  
            //FileStream writer = new FileStream("D://test.html", FileMode.OpenOrCreate, FileAccess.Write);
            //byte[] buff = new byte[512];
            //int c = 0; //实际读取的字节数   
            //while ((c = reader.Read(buff, 0, buff.Length)) > 0)
            //{
            //    writer.Write(buff, 0, c);
            //}
            //writer.Close();
            //writer.Dispose();   


            //reader.Close();
            //reader.Dispose();
            //response.Close();  
        }
    }
}
